#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2009 Denis Mingulov
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


import os
import wsgiref.handlers

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from google.appengine.dist import use_library
use_library('django', '1.1')

from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.api import memcache
from google.appengine.ext.webapp import template

#from engine import moduletypes
from engine import persons

#import install
#import install_mod
#import install_specabil

class MainHandler(webapp.RequestHandler):
    def get_page_data(self, isLoggedIn):
        hashString = "htmlPageIndex_loggedIn%d" % (isLoggedIn)
        data = memcache.get( hashString )
        if data is not None:
            return data
        else:
            template_values = {
                'title': 'SQ Primerka',
                'keywords': 'SQ Primerka',
                'description': 'SQ Primerka',
                'isLoggedIn': isLoggedIn,
                }
     
            path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
            data = template.render(path, template_values)
            memcache.set(hashString, data)
            return data

    def get(self):
        #install.generateModules()
        #install_mod.generateModuleTypeGroups()

#        generate = self.request.get('generate')
        #if len(generate)>0:
        #    eval('install.generateModule'+generate)

        #generate2 = self.request.get('generate2')
        #if len(generate2)>0:
            #eval('install_specabil.generateSpecabil'+generate2)

        #flushall = self.request.get('flushall')
        #if len(flushall)>0:
            #memcache.flush_all()
        isLoggedIn = False;

        self.response.out.write(self.get_page_data(isLoggedIn))


def main():
    application = webapp.WSGIApplication([('/', MainHandler)], debug=True)
    wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
    main()
